package com.leetcode.August;

/**
 * @Description: 74. 搜索二维矩阵
 * @Author: Mr.Fxy
 * @CreateTime: 2024-09-11 22:08
 */
public class LC74搜索二维矩阵 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        if (m == 0 || n == 0) return false;
        for (int i = 0; i < m; i++){
            int low=0, high=n-1;
            while (low <= high){
                int mid=(low+high)/2;
                if (matrix[i][mid] == target){
                    return true;
                }else if (matrix[i][mid]<target){
                    low+=1;
                }else{
                    high-=1;
                }
            }
        }
        return false;
    }
}
